package blog.ideablog.config;

import blog.ideablog.model.comm.BlogSetting;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.setting.Setting;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.File;

@Slf4j
@Configuration
public class BlogSettingConfig {
    @Value("${setting.path}")
    private String settingFilePath;

    @Bean
    public Setting setting() {
        File file = new File(settingFilePath);
        Setting setting;
        if (!file.exists()) {
            setting = new Setting(file, CharsetUtil.CHARSET_UTF_8, false);
            setting.set("title", "ReganC森道夫");
            setting.set("desc", "白内障看不清，硫酸兑水滴眼睛。");
            setting.set("covers", "https://i.postimg.cc/dtLyB0Dc/psb-31.jpg,https://i.postimg.cc/dtLyB0Dc/psb-31.jpg,https://i.postimg.cc/dtLyB0Dc/psb-31.jpg");
            setting.set("avatar", "https://foruda.gitee.com/avatar/1668671213433941925/11450509_regan0142_1668671213.png");
            setting.set("nickname", "兑水");
            setting.store(file.getAbsolutePath());

        }
        setting = new Setting(file, CharsetUtil.CHARSET_UTF_8, false);
        setting.autoLoad(true);
        log.info(BlogSetting.fromSetting(setting).toString());
        return setting;

    }

}
